<?php

namespace app\index\controller;

use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use AlibabaCloud\Tea\Tea;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use think\facade\Config as Configs;

class Sms{
    /**
     * 使用AK&SK初始化账号Client
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Dysmsapi Client
     */
    public static function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([
            // 您的AccessKey ID
            "accessKeyId" => Configs::get("AliSms")["accessKeyId"],
            // 您的AccessKey Secret
            "accessKeySecret" => Configs::get("AliSms")["accessKeySecret"]
        ]);
        // 访问的域名
        $config->endpoint = "dysmsapi.aliyuncs.com";
        return new Dysmsapi($config);
    }

    /**
     * @param string[] $args
     * @return object
     */
    public static function main($args){
        $client = self::createClient(Configs::get("AliSms")["accessKeyId"], Configs::get("AliSms")["accessKeySecret"]);
        $sendSmsRequest = new SendSmsRequest($args);
        // 复制代码运行请自行打印 API 的返回值
        return $client->sendSms($sendSmsRequest);
    }
}
